﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LiveSSOForDotNet.Business;
namespace LiveSSOForDotNet
{
    public partial class Default : System.Web.UI.Page
    {
        const string LoginCookie = "webauthtoken";

        // Initialize the WindowsLiveLogin module.
        static WindowsLiveLogin wll = new WindowsLiveLogin(true);

        protected static string AppId = wll.AppId;

        private Users users_sql = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            users_sql = new Users();
            HttpRequest req = HttpContext.Current.Request;
            HttpResponse res = HttpContext.Current.Response;
            HttpCookie loginCookie = req.Cookies[LoginCookie];
            string windowsLiveID = "";
            if (loginCookie != null)
            {
                string token = loginCookie.Value;

                if (!string.IsNullOrEmpty(token))
                {
                    WindowsLiveLogin.User user = wll.ProcessToken(token);

                    if (user != null)
                    {
                        lblUser.Visible = true;
                        windowsLiveID = user.Id;
                        string userID_sql = users_sql.GetUsers(windowsLiveID);
                        lblUser.Text += "" + userID_sql;
                    }
                }
                else
                {
                    lblUser.Visible = false;
                }
            }
        }
    }
}
